//
//  OTATargetType.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/25.
//

import UIKit
import Moya

public enum OTATargetType {
    
    /// 生产版
    case production(mac: String, version: String)
    
    /// beta版
    case beta(mac: String, version: String)
    
    /// 强制升级
    case forced(mac: String, version: String)
    
    public var type: Int {
        
        switch self {
            
        case .production:
            return 1
            
        case .beta:
            return 2
            
        case .forced:
            return 3
        }
        
    }
    
    /// 参数
    public var parameters: [String: Any] {
        
        var parameters = [String:Any]()
        switch self {
            
        case .production(let mac, let version):
            parameters["version"] = version
            parameters["mac"] = mac
//            parameters["type"] = self.type
            break
            
        case .beta(let mac, let version):
            parameters["version"] = version
            parameters["mac"] = mac
//            parameters["type"] = self.type
            break
        case .forced(mac: let mac, version: let version):
            parameters["version"] = version
            parameters["mac"] = mac
//            parameters["type"] = self.type
        }
        
        return parameters
        
    }

}


extension OTATargetType: APITargetType {
    
    public var path: String {
        switch self {
        case .production:
            return "/v2/upgrade/factory"
        case .beta:
            return "/v2/upgrade/beta"
        case .forced:
            return "/v2/upgrade/factory"
        }

    }

    public var method: Moya.Method {
        return .get
    }

    public var task: Task {
        
        return .requestParameters(parameters: self.parameters, encoding: URLEncoding.default)
        
    }
    
}
